const txtEl = document.querySelector(".txt");
const ulEl = document.querySelector(".todo-list");

txtEl.addEventListener("keydown", function (e) {
  if (e.key === "Enter") {
    if (!this.value.trim()) return;
    const li = document.createElement("li");
    const span = document.createElement("span");
    span.innerHTML = this.value;
    li.appendChild(span);
    const button = document.createElement("button");
    button.innerText = "删除";
    li.appendChild(button);
    ulEl.appendChild(li);
    this.value = "";

    button.addEventListener("click", function () {
      li.remove();
    });
  }
});
